#include <ctime>
#include <unordered_map>
#include <vector>
using namespace std;

class RandomizedSet {
private:
    vector<int> nums;
    unordered_map<int, int> v2i;

public:
    RandomizedSet() : nums(vector<int>(0)) { srand((unsigned int)time(nullptr)); }

    bool insert(int val) {
        if (v2i.count(val)) return 0;
        nums.emplace_back(val);
        v2i[val] = nums.size() - 1;
        return 1;
    }

    bool remove(int val) {
        if (!v2i.count(val)) return 0;
        int old = v2i[val];
        nums[old] = nums.back();
        v2i[nums.back()] = old;
        v2i.erase(val);
        nums.pop_back();
        return 1;
    }

    int getRandom() {
        int r = rand() % nums.size();
        return nums[r];
    }
};